package com.maycurobj;

import com.alibaba.fastjson.JSONObject;
import com.maycur.developer.sdk.common.api.MaycurOpenApiClient;
import com.maycur.developer.sdk.maycur.ultimate.openapi.request.budget.PostBudgetRequest;
import com.maycur.developer.uvshttp.request.RequestHandler;
import com.maycurobj.controller.maycur.MaycurPivotController;
import com.maycurobj.controller.maycur.PartnerPivotController;
import com.maycurobj.controller.maycurbase.SuperiorSynchronization;
import com.maycurobj.pojo.MayCurPartner;
import com.maycurobj.service.http.MaycurApiService;
import com.maycurobj.service.impl.DingTalkService;
import com.maycurobj.service.impl.MaycurService;
import com.maycurobj.service.impl.OutVoucherService;
import com.maycurobj.util.DingMessageUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.List;


@SpringBootTest
class MaycurobjApplicationTest2 {
//
    @Autowired
    private MaycurApiService maycurApiService;
    @Autowired
    private MaycurService maycurService;
    @Autowired
    private OutVoucherService outVoucherService;
    @Autowired
    private DingTalkService dingTalkService;
    @Autowired
    private MaycurPivotController testController;
    @Autowired
    private DingMessageUtil dingMessageUtil;
    @Autowired
    private MaycurPivotController maycurPivotController;
    @Autowired
    private PartnerPivotController partnerPivotController;

    @Autowired
    private SuperiorSynchronization superiorSynchronization;

    @Test
    void contextLoads() {
    }

    @Test
    public void test(){
        //            maycurService.getBudget("BU1100","10","2022-06-01",1);
        try {
            PostBudgetRequest req = new PostBudgetRequest();
            req.setOrgBizCode("BU1000");
            req.setSubjectBizCode("10");
//            PostBudgetResponse rsp = .execute(req);
            MaycurOpenApiClient client=this.maycurApiService.getMaycurOpenApiClient();
            RequestHandler handler=client.getClient().getRequestHandler();

            client.execute(null,JSONObject.class);
//            System.out.println(JSONObject.toJSONString(rsp));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Test
    public void interfaceTest3() {
        MayCurPartner partner=new MayCurPartner();
        partner.setName("河南爱尔康科技有限公司fortest");
        partner.setBusinessCode("024101001999");
        partner.setPartnerProperty("公司");
        partner.setPartnerType("供应商");
        partner.setParentName("集团外单位,河南");
        String ret=partnerPivotController.push(partner);
        System.out.println(ret);
    }

    @Test
    public void mutipushTest() {
        List<String> lists = new ArrayList<>();
        lists.add("123");
        lists.add("1234");
        lists.add("1234");
        lists.add("1253");
        lists.add("12w3");
        lists.add("12r3");
        lists.add("12t3");
        lists.add("12f3");
        lists.add("1g23");
        lists.add("12e3");
        lists.add("1w23");

        //n个一组输出
        //每段长度 默认100
        int count = 100;
        //总数
        int size = lists.size();
        //每段长度
        int seg = size / count;
        //是否除尽
        seg = size % count == 0 ? seg : seg + 1;
        List<String> l = null;
        for (int i = 0; i < seg; i++) {
            if (i == seg - 1) {
                l=lists.subList(count * i, size);
                System.out.println("输出:"+l);
            }else{
                l=lists.subList(count * i, count * (i + 1));
                System.out.println("输出:"+l);
            }
        }

    }

    @Test
    public void maycurRefencesForTest(){
        String id="RD211118ZNNJFK0";
        MayCurPartner partner = new MayCurPartner();
        partner.setParentName("四川");
        partner.setBusinessCode("Text1");
        partner.setName("Text1");
        String ret=maycurService.pushReferenceDetail(partner,id);
        System.out.println(ret);

    }

    @Test
    public void maycurRefencesForTest2(){
        String data="RD211118ZNNJFK0";
        MayCurPartner mayCurPartner = new MayCurPartner();
        mayCurPartner.setParentName("宁夏");
        mayCurPartner.setName("宁夏医科大学附属医院");
        mayCurPartner.setBusinessCode("016401005");
        String state=maycurService.pushReferenceDetail(mayCurPartner, data);
        System.out.println("state--->>>>"+state);
    }


}
